// -----------------------------------------------------------------------
//  <copyright file="GetResourceByIdQuery.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2025 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2025-02-21 14:02</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Authorization.Domain.Entities;


namespace DaprPlus.Authorization.Application.Queries;

[AuthConfig(typeof(Resource), ResourceAccessType.RoleLimit, "GetById")]
public class GetResourceByIdQuery(long id) : SingleQuery<ResourceOutDto?>
{
    public long Id { get; set; } = id;
}

public class GetResourceByIdQueryHandler(IQueryRepository<Resource> queryRepository)
    : IRequestHandler<GetResourceByIdQuery, ResourceOutDto?>
{
    public async Task<ResourceOutDto?> Handle(GetResourceByIdQuery request, CancellationToken cancellationToken)
    {
        var entity = await queryRepository.FindAsync(request.Id, cancellationToken);
        return entity?.MapTo<ResourceOutDto>();
    }
}

